import commands
import nmap
a = commands.getoutput("/sbin/ifconfig").split("\n")[1].split()[1][5:]
#a = "192.37.14.21"
nm = nmap.PortScanner()
# filtro para o range do ip 0.0.0.*
for x in range(4):
	b = a[len(a)-x-1:len(a)-x]
	if b == '.':
		break

b = a[:len(a)-x]+'*'
#print b
#nm.scan(b,'22-443')
nm.scan(hosts = b, arguments = '-n -sP -sV -PA21-443')
#print nm.command_line()
#print nm.scaninfo()
hosts = nm.all_hosts()
port = nmap.PortScannerAsync()
'''
for x in hosts:
	print x
	print port
'''


for host in nm.all_hosts():
        print('----------------------------------------------------')
        print('Host : %s (%s)' % (host, nm[host].hostname()))
        print('State : %s' % nm[host].state())

        for proto in nm[host].all_protocols():
            print('----------')
            print('Protocol : %s' % proto)

            lport = nm[host][proto].keys()
            lport.sort()
            for port in lport:
                print('port : %s\tstate : %s' % (port, nm[host][proto][port]['state']))
